<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="sie-edge"/>
    <link rel="icon" href="/favicon.ico" th:href="@{/favicon.ico}" sizes="32x32">
    <link href="/css/main/bootstrap.min.css" th:href="@{/css/main/bootstrap.min.css}" rel="stylesheet">
    <link href="/css/font-awesome.css" th:href="@{/css/font-awesome.css}" rel="stylesheet">
    <link rel="stylesheet" href="/css/tmp-index-style.css" th:href="@{/css/tmp-index-style.css}">
    <title>EasyShare-密码修改页</title>
    <link rel="stylesheet" type="text/css" href="/css/tmp-index-test.css" th:href="@{/css/tmp-index-test.css}">
    <link rel="stylesheet" href="/css/tmp-index-tip.css" th:href="@{/css/tmp-index-tip.css}">
    <style type="text/css">
        h1 {
            font-weight: bold;
            margin: 0;
            color: beige;
        }
    </style>
    <script src="js/tmp-index-tip.js" th:src="@{/js/tmp-index-tip.js}"></script>
    <script src="js/jquery-3.1.1.min.js" th:src="@{/js/jquery-3.1.1.min.js}"></script>
    <script type="text/javascript">
        $.hulla = new hullabaloo();

        function formSubmit() {
            var uid = $("input[name='userid']").val();
            var userpassword = $("input[name='userpassword']").val();
            var newpassword = $("input[name='newpassword']").val();
            var renewpassword = $("input[name='renewpassword']").val();
            if (userpassword.trim() == "") {
                $.hulla.send("请填写您的原密码", "warning");
                return false;
            }
            if (userpassword == newpassword) {
                $.hulla.send("新密码不能与原密码一致", "warning");
                return false;
            }
            if (newpassword.trim() == "") {
                $.hulla.send("请填写您的新密码", "warning");
                return false;
            }
            if (newpassword != renewpassword) {
                $.hulla.send("两次密码不一致", "warning");
                return false;
            }
            $.ajax({
                type: "POST",
                url: "/user/fixPass",
                data: {uid: parseInt(uid), pass: userpassword, newPass: newpassword},
                dataType: "json",
                success: function (data) {
                    if (data.flag == "ne") {
                        $.hulla.send("原密码错误", "warning");
                    } else if (data.flag == "success") {
                        $.hulla.send("修改成功", "success");
                        $("#formClear").click();
                    } else if (data.flag == "exception") {
                        $.hulla.send("修改失败，请联系系统管理员咨询", "warning");
                    } else {
                        $.hulla.send("??????", "warning");
                    }
                }, error() {
                    $.hulla.send("未知错误，请联系系统管理员咨询", "error");
                    return false;
                }
            });
        }
    </script>

</head>

<body>
<span th:if="${session.user eq null}">
    <script type="text/javascript">
        location.href = "/";
    </script>
</span>
<input type="hidden" id="tip" th:value="${session.tip}">
<div class="container" id="container">
    <div class="form-container sign-in-container">
        <form action="javasciprt:;" method="post" id="fixpass-from" onsubmit="formSubmit()">
            <h1>修改密码</h1>
            <br>
            <span>本站快速修改</span>
            <input type="hidden" name="userid" th:value="${session.user?.getUserid()}">
            <input name="userpassword" type="text" maxlength="11" placeholder="原密码">
            <input name="newpassword" type="password" maxlength="11" placeholder="新密码">
            <input name="renewpassword" type="password" maxlength="11" placeholder="确认新密码">
            <button>修改</button>
            <button type="reset" style="display: none" id="formClear"></button>
        </form>
    </div>
    <div class="overlay-container">
        <div class="overlay">
            <div class="overlay-panel overlay-right">
                <h1>欢迎光临</h1>
                <p>此处免去大量验证以快速修改您的密码<br>如果是第三方登录，则本站不提供修改服务<br>密码可以是任意字符</p>
            </div>
        </div>
    </div>
</div>

<script src="/js/tmp-index-script.js" th:src="@{/js/tmp-index-script.js}"></script>

</body>
</html>
